package com.iris.live.services.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 系统统一的异常处理，只处理业务异常和JAVA报的运行异常
 * <p>
 * Created by Tony.Zhang on 2016/12/19.
 */
@ControllerAdvice(annotations = {RestController.class})
public class RestExceptionHandler {
    private static Logger logger = LoggerFactory.getLogger(RestExceptionHandler.class);

    @ExceptionHandler(value = {Exception.class})
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public void exception(Exception exception, HttpServletRequest request) throws Exception {
        logger.error(request.getRequestURL().toString(), exception);

        throw exception;
    }
}
